package com.comall.dc.banktest.domain.model;

import com.comall.dc.banktest.infrastructure.core.BalanceOperationEnum;
import com.comall.dc.banktest.infrastructure.entity.AccountRecordPO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;


@Getter
@NoArgsConstructor
public class AccountRecord {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "ID")
    private Integer id;

    @ApiModelProperty(value = "账户操作(0:存款, 1:取款, 2:转账)")
    private BalanceOperationEnum operation;

    @ApiModelProperty(value = "来源账户ID")
    private Integer fromAccountId;

    @ApiModelProperty(value = "目的账户ID, 可能为空")
    private Integer toAccountId;

    @ApiModelProperty(value = "操作金额")
    private BigDecimal value;

    @ApiModelProperty(value = "创建时间, 操作时间")
    private LocalDateTime createTime;

    public AccountRecord(AccountRecordPO accountRecordPO){
        this.id = accountRecordPO.getId();
        this.operation = BalanceOperationEnum.of(accountRecordPO.getOperation());
        this.fromAccountId = accountRecordPO.getFromAccountId();
        this.toAccountId = accountRecordPO.getToAccountId();
        this.value = accountRecordPO.getValue();
        this.createTime = accountRecordPO.getCreateTime();
    }

    public AccountRecord(BalanceOperationEnum operation, Integer fromAccountId, Integer toAccountId, BigDecimal value){
        this.operation = operation;
        this.fromAccountId = fromAccountId;
        this.toAccountId = toAccountId;
        this.value = value;
    }
}
